<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>我的</title>
    <link href="../../css/mui.min.css" rel="stylesheet"/>
    <!--<link href="../css/list.css" rel="stylesheet" />-->
    <link href="../../admin/css/style.css" rel="stylesheet" />
    <script src="../../js/app.js"></script>
    <script src="../../js/mui.min.js"></script> 
    <style type="text/css">
    	.mui-btn{
    		padding: 3px;
    		margin: auto 5px;
    	}
    </style>
	</head>
	<body>
<!--		<li class="mui-table-view-cell" style="color:#616161" id="tid'+result.id+'"><div style="font-size:0.9em"><span style="color:#000" onclick="goto(\'item\',\'user\',\'detail\','+result.tid+')"><span style="margin:auto 5px">['+payments+']</span>流水号：'+result.code+','+result.title+'</span><br><span style="font-size:0.8em">订单金额：'+result.sum+'元</span><span style="margin:auto 5px;font-size:0.5em;">'+createtime+'</span></div><p onclick="goto(\'item\',\'admin\',\'orders_detail\','+result.id+')"><span>备注:'+result.notes+'</span></p><div class="list-head" ><span id="status'+result.id+'">'+status(result.status,result.id)+'</span><div class="mui-btn"onclick="goto(\''+result.relation+'\',\'home\',\'detail\','+result.relation_id+')">'+relation+'</div><div class="mui-btn"onclick="goto(\''+result.relation+'\',\'admin\',\'orders_detail\','+result.id+')">订单信息</div><div class="mui-btn"onclick="del('+result.id+')">删除订单</div><span style="color:red;font-size:0.7em">'+state+'</span></div></li>-->
				<script id="tmp_list1" type="text/html">
		<% for(var i in items){ var item=items[i]; var sum=item.income+item.sum; %>
				<% if(item.income=="+"){ var colors="color:#008B00";var income="进账";}else if(item.income=="-"){var colors="color:red";var income="出账";}else{var colors="red";var income="未完成";var sum=item.sum; } %>
						<li class="mui-table-view-cell" style="color:#616161" id="tid<%= item.id %>">
								<div style="text-align: center;font-size: 1.2em;line-height: 1.8em;">
									<span><%= item.relation_title %></span>
									<br><span style="font-size:1.8em;<%= colors %>"><%= sum %>元</span>
									<br><span >[<%= income %>]</span>
								</div>
								
							<div style="margin-top: 30px;font-size: 0.8em;">

								<span style="float: left;width: 25%;">付款方式:
								</span>
								<span style="color:#000;float: right;width: 75%;" onclick="goto('item','user','detail','<%= item.tid %>')">
									<%= item.payments %>
								</span>
								<div style="float:left;width: 100%"></div>

								<span style="float: left;">商品说明:
								</span>
								<span style="color:#000;float: right;width: 75%;" onclick="goto('item','user','detail','<%= item.tid %>')">
									<%= item.title %>
								</span>
								<div style="width: 100%;float:left"></div>

								<span style="float: left;">收货地址:
								</span>
								<span style="color:#000;float: right;width: 75%;" onclick="goto('item','user','detail','<%= item.tid %>')">
									<%= item.address %>
								</span>
								<div style="width: 100%;float:left"></div>

								<span style="float: left;">物流信息:
								</span>
								<span style="color:#000;float: right;width: 75%;" onclick="goto('item','user','detail','<%= item.tid %>')">
									<%= item.logistics %>
								</span>
								
								<div style="width: 100%;float:left"></div>
								<span style="float: left;">物流单号:
								</span>
								<span style="color:#000;float: right;width: 75%;" onclick="goto('item','user','detail','<%= item.tid %>')">
									<%= item.logistics_code %>
								</span>
								
								<div style="width: 100%;float:left"></div>
								<span style="float: left;">账单分类:
								</span>
								<span style="color:#000;float: right;width: 75%;">
									<%= item.breakdown %>
								</span>
								<div style="width: 100%;float:left"></div>
							</div>
							<li class="mui-table-view-cell" style="color:#616161" id="tid<%= item.id %>">
							<p onclick="goto('item','admin','orders_detail','<%= item.id %>')">
								<span style="float: left;">创建时间:
								</span>
								<span style="color:#000;float: right;width: 75%;">
									<%= item.createtime %>
								</span>
								<br>
								<span style="float: left;">订单号:
								</span>
								<span style="color:#000;float: right;width: 75%;">
									<%= item.code %>
								</span>
								<br>
								<span style="float: left;">商户单号:
								</span>
								<span style="color:#000;float: right;width: 75%;" >
									<%= item.code_a %>
								</span>
								<br>
								<span style="float: left;">备注:
								</span>
								<span style="color:#000;float: right;width: 75%;" >
									<%= item.notes %>
								</span>
							</p>
							
							</li>
							
							<!--<div class="list-head" ><span id="status<%= item.id %>"><% item.status %></span>
								<div class="mui-btn"onclick="goto('<%= item.relation %>','home','detail','<%= item.relation_id %>')"><%= item.relation_title %>
									
								</div>
								<div class="mui-btn"onclick="goto('<%= item.relation %>','admin','orders_detail','<%= item.id %>')">订单信息
								</div>
								<div class="mui-btn"onclick="del('<%= item.id %>')">删除订单
								</div>
								<span style="color:red;font-size:0.7em"><%= item.state %></span>
							</div>-->
						</li>

		<% } %>
		</script>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">账单详情</h1>
		</header>
		<div class="mui-content" id="pullrefresh">
			<ul class="mui-table-view" >
				<div id="content"></div>
			       <div class="friend-list-left" id="item"></div>
		    </ul>
	    </div>
	</body>
	<script src="../../js/cache/img.js"></script>
	<script src="../../js/lib/arttmpl.js"></script>
	<script type="text/javascript">
		apptoken['tid']=tid;
item();
function item(){//我发布的项目

//		alert(JSON.stringify(apptoken));
		 apptoken['act']='detail';
mui.post(home.hos+'/wallet_orders/admin?tid='+apptoken['tid'],apptoken,function(data){
		 	alert('订单详情'+JSON.stringify(data));
		var result=JSON.parse(data);
		 var val='';
//	for(var i=0;i<result.length;i++){

		switch(result.relation){
//		case 'wallet':
//		var relation='钱包';
//		  break;
//		case 'money':
//		var relation='资金';
//		  break;
//		  case 'source':
//		var relation='资源';
//		  break;
		  case 'item':
		  var relation='项目';
		  break;
		default:
		var relation='其他';
		}
if(result.state=='1'){
	state='';
}else{
	state='对方已关闭';
}

if(result.user_id==my.id){var income='-'}else{var income="+"};
		var createtime=new Date(parseInt(result.createtime) * 1000).format('yyyy年M月d日 hh:mm:ss');

			data={
						items:[{
//							tid:result.relation_id,//商品id
							id:result.id,//支付id
							code:result.code,//支付编号
							code_a:result.code_a,//商户编号
							address:result.address,//收件地址
							breakdown:result.breakdown,//账单分类
							logistics:result.logistics,//物流公司
							logistics_code:result.logistics_code,//物流单号
							title:result.title,//商品信息
							user_id:result.user_id,//用户id
							income:income,//支付进出
							payments:result.payments,//付款方式
							relation:result.relation,//商品来源
							relation_title:relation,//来源标题
							relation_id:result.relation_id,//商品id
//							status:status(result.status,result.id),
							sum:result.sum,//金额
							state:state,//状态
							notes:result.notes,//备注
//							speciality:result.code,
							createtime:createtime//下单时间
						}],
						src:home.uploads+'/img/resume/'
				};
			html = template('tmp_list1', data);
			document.querySelector("#content").innerHTML += html;
			//优先读取本地缓存图片,没有在网络下载;
//	        setImg(imgs, home.uploads+'/img/resume/min'+imgs,'resume');
//	};

//	document.getElementById("item").innerHTML+=val;
			//服务器返回响应，根据响应结果，分析是否登录成功；
	//		...
		},'text');
}



//签约状态返回值
function status(status,tid){
	var tid=tid||'';
//	alert(status+','+parseInt(status));
	switch(parseInt(status)){
		case 0:
		arr= ['对方未授权',''];
		  break;
		case 1:
		arr= ['请联系对方签约纸质合同','完成签约'];
		  break;
		  case 2:
		arr= ['签约完成','立即结算'];
		  break;
		  case 3:
		  arr= ['对方未收款',''];
		  break;
		default:
		arr= ['已结束',''];
		}
if(arr[1] && arr[1]!=''){
		statustr='<div class="mui-btn mui-btn-danger mui-btn-outlined"style="padding:3px"onclick="modify('+tid+',\'status\','+status+',this)">'+arr[1]+'</div>';	
		}else{
			statustr='';
		}
		return '<div style="font-size:0.7em;color:red" ><span>'+arr[0]+'</span></div>'+statustr+'';
}
//修改
function modify(tid,type,v,html){
//	alert(status(v,tid));
	//k=键；act=修改方法，tid=主题id，type=修改类型；
	apptoken['k']=type||'';
	apptoken['v']=v ||'';
	apptoken['tid']=tid||'';
	apptoken['act']='modify';
//	alert(JSON.stringify(apptoken));
//	return false;
 mui.prompt('请输入授权码', '密码','' , ['取消','确认'], function(e) {
        if (e.index == 1) {
apptoken['ps']=e.value;
 	mui.post(home.hos+'/item_orders/admin',apptoken,function(data){
			if(data==1){
				htmla=document.getElementById('status'+tid);
   				htmla.innerHTML=status((v+1),tid);
//				document.getElementById(type).innerText=value.value;
			}else{
				plus.ui.toast('操作失败'+data);
			}
	})}else{
		plus.ui.toast('操作已取消');
	}},'div')
}
function del(tid){
	html=document.getElementById('tid'+tid);
//	alert(tid+html);
	mui.confirm('删除后不能恢复,确认删除码？', '', ['取消', '确认'], function(e) {
	apptoken['tid']=tid||'';
	apptoken['act']='delete';
// 	return false;
 	mui.post(home.hos+'/item_orders/admin',apptoken,function(data){
//		alert(data);
			if(data==1){
				document.getElementById("item").removeChild(html);
//				html=value.value;
			}else{
				plus.ui.toast('操作失败');
			}
	})
 });

}
//function goto(module,room,htmlname,this_id){//我的微博
//	localStorage[module+room+htmlname+'id']=this_id;
//	mui.openWindow('../../'+module+'/'+room+'/'+htmlname+'.html');
//	}
</script>